using WebExam.Core.Common;

namespace WebExam.Core.Security
{
    public static class CryptographyManager
    {
        #region Public Method

        public static string EncodePassowrd(string plainText)
        {
            return LoadProvider().Encrypting(plainText);
        }

        public static string DecodePassword(string cypherText)
        {
            return LoadProvider().Decrypting(cypherText);
        }

        #endregion

        #region Private method

        private static ICryptographyProvider LoadProvider()
        {
            ICryptographyProvider result = CryptoFactory.NonCrptoCreate();

            switch (Utilities.PasswordFormat)
            {
                case PasswordFormat.Encrypted:
                    result = CryptoFactory.SymmetricCreate();
                    break;
                case PasswordFormat.Hashed:
                    result = CryptoFactory.HashCreate();
                    break;
                default:
                    result = CryptoFactory.NonCrptoCreate();
                    break;
            }

            return result;
        }

        #endregion
    }
}